# 创建集合
set1 = {1, 2, 4, 5, 3, 7}
# 添加元素
set1.add(8)
print('set1 = ', set1, end='\n')
set1.update({9, 10})
print('set1 = ', set1, end='\n')
set1.update([11, 12])
print('set1 = ', set1, end='\n')
set1.discard(5)
print('set1 discard = ', set1, end='\n')
set1.discard(100)
print('set1 discard = ', set1, end='\n')
set1.remove(3)
print('set1 remove = ', set1, end='\n')
# KeyError
# set1.remove(100)

# 创建集合的构造器语法
set2 = set(range(1, 10))
print('set2 = ', set2, end='\n')
set3 = set((1, 2, 3, 5))
print('set3 = ', set3, end='\n')

# 创建集合的推导式语法
set4 = {num for num in range(1, 10) if num % 3 == 0 or num % 5 == 0}
print('set4 = ', set4, end='\n')

set1 = {1, 2, 3, 4, 5}
set2 = {3, 4, 5, 6, 7}
# 取交集
print('intersection = ', set1.intersection(set2), end='\n')
print('set1 & set2', set1 & set2, end='\n')
# 取并集
print('union = ', set1.union(set2), end='\n')
print('set1 | set2', set1 | set2, end='\n')
# 取差集
print('difference = ', set1.difference(set2), end='\n')
print('set1 - set2', set1 - set2, end='\n')
# 取不同
print('symmetric_difference', set1.symmetric_difference(set2), end='\n')
print('set1 ^ set2', set1 ^ set2, end='\n')

set1 = {1, 2, 3, 4, 5}
set2 = {1, 2, 3}
# 判断子集
print('set1 is subset of set2: ', set1.issubset(set2), end='\n')
print('set2 is subset of set1: ', set2.issubset(set1), end='\n')
# 判断超集
print('set1 is superset of set2: ', set1.issuperset(set2), end='\n')
print('set2 is superset of set1: ', set2.issuperset(set1), end='\n')
